// 引入公共css
require("../../assets/css/normalize.css");
require("../../assets/css/reset.css");
require("../../assets/css/basic.css");
require("../../assets/css/property.css");
require("../../assets/fonts/word-img/iconfont.css");
let dom = require("../../assets/js/util.js");
let axios = require("../../assets/js/axios");

// 引入自己的
require("./maping.less");
window.addEventListener("DOMContentLoaded", function () {
	// map
	var map = new BMapGL.Map("container");
	var point = new BMapGL.Point(116.404, 39.915);
	map.centerAndZoom(point, 15);
	//普通
	// 渲染
	// 获取参数type
	let type = location.search.split("=").pop();
	// 请求数据
	axios.get("/api/exercise").then((res) => {
		// 每天的数据
		let days = res.data.data.days;

		if (res.data.errno === 0) {
			// 当天
			let current = days[days.length - 1];
			console.log(current);
			// 当天锻炼数据
			currentData = current.exerciseData[type];
			console.log(currentData);
			// 渲染
			let speed = currentData.meter / currentData.duration;
			console.log(currentData.meter, currentData.duration);
			dom.$("#speed").textContent = speed.toFixed(2);
			dom.$("#time").textContent = currentData.duration;
			dom.$("#distance").textContent = currentData.meter.toFixed(2);
			// 渲染
		}
	});
	// 箭头
	// dom.turnToPage("sports-run", "main .icon-left2");
	dom.$("main .icon-left2").addEventListener("click", function () {
		// 根据type的类型不同，跳转想应页面
		if (type === 0) {
			location.href = "sports-run.html";
		} else {
			location.href = "sport-ride.html";
		}
	});
});
